From 02107fc437abc4137ea7ff633cf0e27433a00c56 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 28 Jul 2011 10:05:33 -0700 Subject: [PATCH] * alloc.c (memory_full) [!SYNC_INPUT]: Fix signal-related race. Without this fix, if a signal arrives just after memory fills up, 'malloc' might be invoked reentrantly. --- src/ChangeLog | 4 ++++ src/alloc.c | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index bf43a861e27..d34add52480 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,9 @@ 2011-07-28 Paul Eggert + * alloc.c (memory_full) [!SYNC_INPUT]: Fix signal-related race. + Without this fix, if a signal arrives just after memory fills up, + 'malloc' might be invoked reentrantly. + * image.c (x_check_image_size) [!HAVE_X_WINDOWS]: Return 1. In other words, assume that every image size is allowed, on non-X hosts. This assumption is probably wrong, but it lets Emacs compile. diff --git a/src/alloc.c b/src/alloc.c index eb0185a8e35..b96fc1f0642 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -3282,12 +3282,16 @@ memory_full (size_t nbytes) int enough_free_memory = 0; if (SPARE_MEMORY < nbytes) { - void *p = malloc (SPARE_MEMORY); + void *p; + + MALLOC_BLOCK_INPUT; + p = malloc (SPARE_MEMORY); if (p) { free (p); enough_free_memory = 1; } + MALLOC_UNBLOCK_INPUT; } if (! enough_free_memory) -- 2.30.2